package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ISetmealDishService;
import com.sky.service.ISetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐分类
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private ISetmealService setmealService;

   /* @Autowired
    private ISetmealDishService setmealDishService;*/

    /**
     * 新增套餐
     * @param sDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加套餐")
    public Result add(@RequestBody SetmealDTO sDTO){
        setmealService.addSetmeal(sDTO);
        return Result.success();
    }
    /**
     * 套餐分页查询
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO sDTO){
        PageResult pageResult = setmealService.pageQuery(sDTO);
        return Result.success(pageResult);

    }

    /**
     * 根据ID查询套餐
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("查询套餐：{}", id);
        SetmealVO setmealVO = setmealService.findById(id);
        return Result.success(setmealVO);
    }

    /**
     * 批量删除套餐
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids){
        log.info("批量删除套餐：{}", ids);
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 套餐起售、停售
     */
    @PostMapping("/status/{status}")
    public Result<PageResult> startOrStop(@PathVariable Integer status, Long id){
        log.info("套餐起售、停售：{}", status);
        setmealService.startOrStop(status, id);
        return Result.success();
    }
    /**
     * 修改套餐
     */
    @PutMapping
    public Result edit(@RequestBody SetmealDTO sDTO){
        log.info("修改套餐：{}", sDTO);
        setmealService.editSetmeal(sDTO);
        return Result.success();
    }
}
